'''
#--  @owner:opentestcase005
#--  @date:2020/9/17
#--  @testpoint:修改词典，权限测试（sysadmin用户）
'''

import unittest
from yat.test import macro
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant
from testcase.utils.CommonSH import CommonSH


logger = Logger()
commonsh = CommonSH('dbuser')
constant = Constant()

class Hostname(unittest.TestCase):

    def setUp(self):
        logger.info("------------------------Opengauss_BaseFunc_Full_Text_Search_dictionary_0035开始执行--------------------------")

    # 创建Ispell词典, FILEPATH使用本地目录（/Datadir/cluster/app/share/postgresql/tsearch_data）
    def test_directoary_1(self):
        file_path = macro.DB_DictFile
        SqlMdg = commonsh.execut_db_sql('''drop TEXT SEARCH DICTIONARY if exists snowball_test cascade;''')
        logger.info(SqlMdg)
        self.assertIn(constant.DROP_DICTIONARY_SUCCESS_MSG, SqlMdg)

        SqlMdg = commonsh.execut_db_sql(f'''CREATE TEXT SEARCH DICTIONARY snowball_test (
                                      TEMPLATE = snowball,
                                      LANGUAGE = 'english',
                                      STOPWORDS = 'english',
                                      FILEPATH = 'file:{file_path}');''')
        logger.info(SqlMdg)
        self.assertIn(constant.CREATE_DICTIONARY_SUCCESS_MSG, SqlMdg)
        # sysadmin用户更改Snowball类型字典的停用词定义，其他参数保持不变（sysadmin用户有权限执行alter命令）
        SqlMdg = commonsh.execut_db_sql('''ALTER TEXT SEARCH DICTIONARY snowball_test (StopWords = 'russian');''')
        logger.info(SqlMdg)
        self.assertIn('ALTER TEXT SEARCH DICTIONARY', SqlMdg)

       # 删除词典
    def tearDown(self):
        logger.info('----------this is teardown-------')
        SqlMdg = commonsh.execut_db_sql('''drop TEXT SEARCH DICTIONARY snowball_test cascade;''')
        logger.info(SqlMdg)
        self.assertIn(constant.DROP_DICTIONARY_SUCCESS_MSG, SqlMdg)
        logger.info('------------------------Opengauss_BaseFunc_Full_Text_Search_dictionary_0035执行结束--------------------------')
